package main

import (
	"fmt"
	"html/template"
	"net/http"
)

func nest(w http.ResponseWriter,r *http.Request)  {
	// 不能写成template.ParseFiles("./ul.tmpl","./test.tmpl","./ol.tmpl")
	// 因为是test.tmpl是主模板，ul.tmpl和ol.tmpl需要等主模板解析完之后在解析
	t, err := template.ParseFiles("./test.tmpl","./ul.tmpl","./ol.tmpl")
	if err != nil {
		fmt.Printf("parse file failed err := %v",err)
	}
	mp := map[string]interface{}{
		"name": "张大炮",
		"sex": "女",
	}
	err = t.Execute(w, mp)
	if err != nil {
		fmt.Printf("execute file failed err := %v",err)
	}
}

func main() {
	http.HandleFunc("/",nest)
	err := http.ListenAndServe(":9000", nil)
	if err != nil {
		fmt.Printf("listen address failed err = %v",err)
	}
}
